package com.chaoyong.higo.base;


import com.chaoyong.higo.utils.DatabaseHelper;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.umeng.socialize.PlatformConfig;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Build;

public class BaseApp extends Application {
	static Context _context;
	public static IWXAPI iwxapi;

	private final static String APP_ID = "wxd13d827c27bcd2a9";
	@Override
	public void onCreate() {
		super.onCreate();
		_context = this;
		
		iwxapi = WXAPIFactory.createWXAPI(this, APP_ID, true);
		BaseApp.iwxapi.registerApp(APP_ID);
		
		PlatformConfig.setQQZone("1105451502", "FcJVASSPXEwevj4w");
		
		new DatabaseHelper(this).getWritableDatabase().close();
		initImageLoader(_context);
	}
	
	public static Context getContext() {
		return _context;
	}

	private void initImageLoader(Context context) {
		int memoryCacheSize;
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
			int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
			memoryCacheSize = (memClass / 8) * 1024 * 1024; // 1/8 of app memory
															// limit
		} else {
			memoryCacheSize = 2 * 1024 * 1024;
		}
		@SuppressWarnings("deprecation")
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.threadPriority(Thread.NORM_PRIORITY - 2).memoryCacheSize(memoryCacheSize)
				.denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.defaultDisplayImageOptions(new DisplayImageOptions.Builder().cacheInMemory(true)// 启用内存缓存
						.cacheOnDisc(true).build())
				.build();// 启用外存缓存
		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(config);

	}

}
